package com.lzgcoding.onlineshopapp.feature.main.dashboard.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AssistChip
import androidx.compose.material3.AssistChipDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import com.lzgcoding.onlineshopapp.R
import com.lzgcoding.onlineshopapp.room.entity.CategoryEntity
import com.lzgcoding.onlineshopapp.ui.theme.Green
import com.lzgcoding.onlineshopapp.ui.theme.LargePadding
import com.lzgcoding.onlineshopapp.ui.theme.MediumPadding

@Composable
fun ColumnScope.CategoryList(
    categories: List<CategoryEntity>,
    selectedCategoryId: Int,
    onCategorySelected: (CategoryEntity) -> Unit
) {
    Text(
        text = stringResource(R.string.str_category),
        style = MaterialTheme.typography.bodyLarge, fontWeight = FontWeight.Bold,
        modifier = Modifier
            .fillMaxWidth()
            .padding(horizontal = LargePadding)
            .padding(top = LargePadding * 2, bottom = MediumPadding),
    )
    LazyRow(
        modifier = Modifier.fillMaxWidth(),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(LargePadding)
    ) {
        item { Spacer(Modifier) }
        items(categories) {
            val selected = selectedCategoryId == it.id
            AssistChip(
                onClick = { onCategorySelected(it) },
                label = {
                    Text(text = it.title)
                },
                shape = RoundedCornerShape(MediumPadding),
                colors = AssistChipDefaults.assistChipColors(
                    containerColor = if (selected) Green else Color.Unspecified,
                    labelColor = if (selected) Color.White else Color.Black
                )
            )
        }
        item { Spacer(Modifier) }
    }
}